package token

import (
	"github.com/dgrijalva/jwt-go"
	"time"
)

type jwtCardCustomClaims struct {
	jwt.StandardClaims

	// 追加自己需要的信息
	Uid      int   `json:"uid"`
	Secret   string `json:"secret"`
}

func CreateCardToken(SecretKey string, issuer string, Uid int) (tokenString string, err error) {
	claims := &jwtCardCustomClaims{
		jwt.StandardClaims{
			ExpiresAt: time.Now().Add(time.Hour * 1).Unix(),
			Issuer:    issuer,
		},
		Uid,
		SecretKey,
	}
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
	tokenString, err = token.SignedString([]byte(SecretKey))
	return
}